package day32.edu;

import org.junit.Test;

import java.io.*;

// Created: 02/10/2025, ChangJiang Ru
public class BufferedStreamTest {
    @Test
    public void test1 () throws Exception
    {
        // Create file object
        File srcFile = new File("boy.png");
        File destFile = new File("boy_copy.png");

        // Create the input and output stream object
        FileInputStream fis = new FileInputStream(srcFile);
        FileOutputStream fos = new FileOutputStream(destFile);

        // Create the input and output buffered stream
        BufferedInputStream bis = new BufferedInputStream(fis);
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        // read input the data
        byte[] buffer = new byte[1024];
        int len;
        while((len = bis.read(buffer)) != -1)
        {
            bos.write(buffer, 0, len);
        }
        System.out.println("Copy Successfully");

        // Close source

        bis.close();
        bos.close();
    }
}
